// 二分查找
var search = function (nums, target) {
  let left = 0,
      right = nums.length - 1;
  while (left <= right) {
    let mid = (left + right) >> 1;
    if (nums[mid] === target) {
      left = mid;
      break;
    } else if (nums[mid] < target) {
      left = mid + 1;
    } else {
      right = mid - 1;
    }
  }

  if (nums[left] !== target) return 0;
  let start = left - 1;
  let end = left + 1;
  let count = 1;
  while (start >= 0 && nums[start] === target) {
    start--;
    count++;
  }

  while (end < nums.length && nums[end] === target) {
    end++;
    count++;
  }
  return count;
}